package com.penngo.yiiboot.base;

import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * ChromeDriver
 */
@Slf4j
public abstract class BaseChromeTest {
    public final String url = "http://localhost:81/yiiboot_master/backend/web/index.php";
    public WebDriver driver = null;

    @BeforeClass
    public void setUpAll(){
        System.out.println("setUpAll===============");
        log.info("setUpAll===============");
        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<>();
//        prefs.put("profile.default_content_setting_values.images", 2);
//        prefs.put("profile.default_content_setting_values.plugins", 2);
//        prefs.put("profile.default_content_setting_values.geolocation", 2);
//        prefs.put("profile.default_content_setting_values.notifications", 2);
        options.setExperimentalOption("prefs", prefs);
        driver = DriverBuilder.createChrome(false, true, options);
    }

    @AfterClass
    public void tearDownAll(){
        System.out.println("tearDownAll===============");
        if(driver != null){
            driver.quit();
        }
    }


    public void sleep(int second){
        try{
            Thread.sleep(second * 1000);
        }
        catch(Exception e){

        }
    }
}
